﻿using B.S.DataBase.MyProject.Domain.Storages;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using T.E.ERP.Read.API.Applicantions.Command.StoragesCommand;

namespace T.E.ERP.Read.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ManagementsController : ControllerBase
    {
        private readonly IMediator mediator;
        private readonly ILogger<ManagementsController> logger;

        public ManagementsController(IMediator mediator, ILogger<ManagementsController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }
        /// <summary>
        /// 仓库列表显示
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<ApiPaging<BaseStorage>>> GetBasestore(int pageindex,int pagesize,string?basecode,string?basename)
        {
            GetStorageCommand command = new GetStorageCommand();
            command.Pageindex = pageindex;
            command.Pagesize = pagesize;
            command.BaseCode = basecode;
            command.BaseName = basename;
            try
            {
                logger.LogInformation("成功调用了仓库列表方法");
            }
            catch (Exception ex)
            {
                logger.LogError(DateTime.Now + "调用失败了！" + ex.Message);
                throw;
            }
            return await mediator.Send(command);
        }
    }
}
